﻿using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;

namespace bpms.Models
{
    /// <summary>
    /// 饮料商品
    /// </summary>
    [Table("Product")]
    public class Product
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required(ErrorMessage = "编号不能为空")]
        [StringLength(50, ErrorMessage = "长度不能超过50个字符")]
        [Display(Name = "编号")]
        [Column("product_no", TypeName = "varchar(50)")]
        public string ProductNo { get; set; }

        [Required(ErrorMessage = "名称不能为空")]
        [StringLength(50, ErrorMessage = "长度不能超过50个字符")]
        [Display(Name = "名称")]
        [Column("name", TypeName = "varchar(50)")]
        public string Name { get; set; }

        [Required(ErrorMessage = "库存不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "库存不能为负数")]
        [Display(Name = "库存数量")]
        [Column("stock", TypeName = "int")]
        public int Stock { get; set; }

        [Required(ErrorMessage = "最低库存不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "最低库存不能为负数")]
        [Display(Name = "最低库存数量")]
        [Column("limit_stock", TypeName = "int")]
        public int LimitStock { get; set; }

        [Required(ErrorMessage = "价格不能为空")]
        [Range(0.01, double.MaxValue, ErrorMessage = "价格必须大于0")]
        [DataType(DataType.Currency)]
        [Display(Name = "产品价格")]
        [Column("price", TypeName = "decimal(10,0)")]
        public decimal Price { get; set; }

        
        [Display(Name = "状态")]
        [Column("status", TypeName = "int")]
        [ValidateNever]
        public int Status { get; set; }

        [StringLength(200)]
        [Display(Name = "图片")]
        [Required(ErrorMessage = "图片必须选择")]
        [Column("image", TypeName = "varchar(200)")]
        [ValidateNever]
        public string Image { get; set; }

        [Display(Name = "供应商")]
        [Required(ErrorMessage = "供应商不能为空")]
        [Column("supplier", TypeName = "varchar(100)")]
        public string Supplier { get; set; }

        [Display(Name = "生产日期")]
        [Required(ErrorMessage = "生产日期不能为空")]
        [Column("produce_date", TypeName = "datetime")]
        public DateTime ProduceDate { get; set; }

        [Required(ErrorMessage = "保质期不能为空")]
        [Range(0, int.MaxValue, ErrorMessage = "保质期不能为负数")]
        [Display(Name = "保质期(月)")]
        [Column("quality_period", TypeName = "int")]
        public int QualityPeriod { get; set; }

       
        [Column("created_time", TypeName = "datetime")]
        [ValidateNever]
        public DateTime CreatedTime { get; set; }

        [Column("created_user", TypeName = "int")]
        [ValidateNever]
        public int CreatedUser { get; set; }
    }
}
